package com.xing.user.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xfh
 * @date 2022/7/27 16:20
 */

//获取当前用户信息工具类
public class AuthContextHolder {

    //获取当前用户id
    public static Long getUserId(HttpServletRequest request) {
        //从header获取token
        String token = request.getHeader("token");
        //jwt从token中获取userid
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    //获取当前用户id
    public static String getUserName(HttpServletRequest request) {
        //从header获取token
        String token = request.getHeader("token");
        //jwt从token中获取userName
        String userName = JwtHelper.getUserName(token);
        return userName;
    }
}
